#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <stdlib.h>
using namespace std;

int cnt=0;

void  handler(int signo)
{
    cout<<"get a signal:"<<signo<<" cnt:"<<cnt<<endl;
    exit(0);
}
int main()
{
    //对信号SIGALRM进行捕获
    signal(SIGALRM,handler);
    alarm(1);//1秒后唤醒
    while(1)
    {
        cnt++;
    }
    return 0;
}
